package qc.module.ehs.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.ehs.dto.hazard.EhsHazardFullInfoDto;
import qc.module.ehs.dto.hazard.EhsHazardInfoDto;
import qc.module.ehs.dto.hazard.EhsHazardUnitQueryConditionDto;
import qc.module.ehs.service.EhsHazardInfoService;

import java.util.List;

/**
 * HazardController
 * 危险源
 *
 * @author QuCheng Tech
 * @create 2024/11/5
 */
@RestController
@RequestMapping("/hazard")
public class HazardController {
    
    @Autowired
    private EhsHazardInfoService service;

    /**
     * 获取指定危险源信息
     *
     * @param id 危险源ID
     * @return EhsHazardInfoDto
     * @author QuCheng Tech
     * @since 2024/11/5
     */
    @GetMapping("/get")
    public EhsHazardInfoDto getByParam(@RequestParam String id) {
        return service.get(id);
    }

    /**
     * 获取指定危险源信息
     *
     * @param id 危险源ID
     * @return EhsHazardInfoDto
     * @author QuCheng Tech
     * @since 2024/11/5
     */
    @GetMapping("/get/{id}")
    public EhsHazardInfoDto getByPath(@PathVariable String id) {
        return service.get(id);
    }

    /**
     * 获取指定危险源完整信息
     *
     * @param id 危险源ID
     * @return EhsHazardFullInfoDto
     * @author QuCheng Tech
     * @since 2024/11/5
     */
    @GetMapping("/full")
    public EhsHazardFullInfoDto getFullInfoByParam(@RequestParam String id) {
        return service.getFullInfo(id);
    }

    /**
     * 获取指定危险源完整信息
     *
     * @param id 危险源ID
     * @return EhsHazardFullInfoDto
     * @author QuCheng Tech
     * @since 2024/11/5
     */
    @GetMapping("/full/{id}")
    public EhsHazardFullInfoDto getFullInfoByPath(@PathVariable String id) {
        return service.getFullInfo(id);
    }

    /**
     * 获取指定单元的危险源集合
     * 用于在危险源辨识记录确认时提供给确认对应的危险源下拉列表使用；
     * 如果有传入类别、项目和清单直接进行匹配；
     * 
     * @param condition 查询条件
     * @return List<EhsHazardInfoDto>
     * @author QuCheng Tech
     * @since 2024/11/13
     */
    @RequestMapping(value = "/unit",method = {RequestMethod.GET,RequestMethod.POST})
    public List<EhsHazardInfoDto> queryUnitHazards(@RequestBody EhsHazardUnitQueryConditionDto condition) throws QCPromptException {
        return service.queryUnitHazards(condition);
    }
}
